package com.aaa.controller;

import com.aaa.Service.StuService;
import com.aaa.entity.Stu;
import com.aaa.util.DefaultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")

//解决跨域问题


public class StuController {

    @Autowired
    private StuService studentService;


@RequestMapping("/listAll")
    public List<Stu> listAll(){
    List<Stu> list = studentService.list();
    return list;
}

@RequestMapping("/saveOrUpdate")
public DefaultMsg saveOrUpdate(Stu student){
    DefaultMsg defaultMsg = new DefaultMsg();
    boolean b = studentService.saveOrUpdate(student);
    if (!b){
        defaultMsg.setSuccess(0);
        defaultMsg.setError("操作失败");
    }
    return defaultMsg;
}

@RequestMapping("/delete")
public boolean delete(Stu student){
    boolean save = studentService.removeById(student.getId());
    return save;
}
}
